package com.yayohos.locationmanager.helper;


import ohos.location.Locator;
import ohos.location.LocatorCallback;
import ohos.location.RequestParam;

/**
 * UpdateRequest
 *
 * @date 2021/5/26
 */
public class UpdateRequest {
    private final Locator locationManager;
    private final LocatorCallback locationListener;
    private RequestParam requestParam;
    private int priority;
    private int minTime;
    private int minDistance;

    public UpdateRequest(Locator locationManager, LocatorCallback locationListener) {
        this.locationManager = locationManager;
        this.locationListener = locationListener;
    }

    /**
     * run
     *
     * @param priority         priority
     * @param timeInterval     timeInterval
     * @param distanceInterval distanceInterval
     */
    public void run(int priority, int timeInterval, int distanceInterval) {
        this.priority = priority;
        this.minTime = timeInterval;
        this.minDistance = distanceInterval;
        requestParam = new RequestParam(this.priority, minTime, minDistance);
        run();
    }

    /**
     * 开始定位
     */
    public void run() {
        if (requestParam != null) {
            locationManager.startLocating(requestParam, locationListener);
        }
    }

    /**
     * 停止定位
     */
    public void release() {
        if (locationManager != null) {
            locationManager.stopLocating(locationListener);
        }
    }

}
